package me.zk.practice1.s;

import java.util.Stack;

/**
 * @author zhangkai
 * @date 2023/7/31 18:30
 */
public class LS155 {

    Stack<Integer> dataStack = null;
    Stack<Integer> minStack = null;
    public LS155() {
        dataStack = new Stack<>();
        minStack = new Stack<>();
    }

    public void push(int val) {
        dataStack.push(val);
        if (minStack.isEmpty()) {
            minStack.push(val);
        } else  if (minStack.peek() >= val) {
            minStack.push(val);
        }
    }

    public void pop() {
        int value = dataStack.pop();
        if (value == minStack.peek()) {
            minStack.pop();
        }
    }

    public int top() {
        return dataStack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }
}
